﻿
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
namespace Calculator
{
    partial class MainPage
    {
        private CalculatorEngine _engine = new CalculatorEngine();

        public MainPage()
        {
            InitializeComponent();
            _engine.PropertyChanged += new PropertyChangedEventHandler(_engine_PropertyChanged);
        }

        void _engine_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            _currentValue.Text = _engine.CurrentValue;
        }

        private void CalcButtonClick(object sender, RoutedEventArgs e)
        {
            var btn = (Button)sender;
            string func = btn.Content.ToString();
            try
            {
                _error.Text = " ";
                _engine.ProcessKey(func);
            }
            catch (Exception ex)
            {
                _error.Text = ex.Message;
            }
        }


        public string CurrentValue
        {
            get { return _currentValue.Text; }
            set { _currentValue.Text = value; }
        }
    }
}
